<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>评估测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 50px;
            background-color: #6a0dad;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100%;
        }
        .container {
            width: 80%;
            max-width: 1000px;
            background-color: white;
            border-radius: 16px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 100);
            overflow: hidden;
        }
        .header {
            background-color: #FF9800;
            color: white;
            padding: 0px;
            text-align: center;
            border: 20px solid #FFFDFD ;
            border-radius: 50px;
        }
        .content {
            padding: 20px;
        }
        .module {
            margin-bottom: 20px;
            border: 1px solid #e0e0e0;
            border-radius: 8px;
            padding: 15px;
            background-color: #f9f9f9;
        }
        .question {
            margin-bottom: 10px;
        }
        .options {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
        }
        .option {
            padding: 10px;
            background-color: #ffffff;
            border: 1px solid #e0e0e0;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s, color 0.3s;
            text-align: center;
            font-size: 16px;
            margin-bottom: 2px;
        }
        .option.selected {
            background-color: #4CAF50;
            color: #fff;
            border-color: #388e3c;
        }
        .option:hover {
            background-color: #f0f0f0;
        }
        .submit-btn {
            display: block;
            width: 100%;
            padding: 12px;
            background-color: #ff9800;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            margin-top: 20px;
        }
        .submit-btn:hover {
            background-color: #f57c00;
        }
        input[type="radio"] {
            width: 18px;
            height: 18px;
            accent-color: #ff9800; /* 让选中时颜色更明显，兼容现代浏览器 */
            vertical-align: middle;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>评估测试</h1>
        </div>
        <div class="content">
            <form method="post" action="{% url 'questionnaire:submit_test' %}">
                {% csrf_token %}
                <input type="hidden" name="question_type" value="{{ question_type }}">
                {% for question in questions %}
                    <div class="module">
                        <div class="question">{{ question.question }}</div>
                        <div class="options">
                            <div class="option" data-qid="{{ question.id }}" data-value="A">{{ question.option_a }}</div>
                            <div class="option" data-qid="{{ question.id }}" data-value="B">{{ question.option_b }}</div>
                            <div class="option" data-qid="{{ question.id }}" data-value="C">{{ question.option_c }}</div>
                            <div class="option" data-qid="{{ question.id }}" data-value="D">{{ question.option_d }}</div>
                            <!-- 隐藏域用于提交答案 -->
                            <input type="hidden" name="question_{{ question.id }}" id="hidden_{{ question.id }}">
                        </div>
                    </div>
                {% endfor %}
                <button class="submit-btn">提交</button>
            </form>
        </div>
        <script>
            // 选项点击事件
            document.querySelectorAll('.options').forEach(function(optionGroup) {
                optionGroup.querySelectorAll('.option').forEach(function(opt) {
                    opt.addEventListener('click', function() {
                        // 取消同组其他选中
                        optionGroup.querySelectorAll('.option').forEach(function(o) {
                            o.classList.remove('selected');
                        });
                        // 当前选中
                        this.classList.add('selected');
                        // 设置隐藏input的值
                        var qid = this.getAttribute('data-qid');
                        var val = this.getAttribute('data-value');
                        document.getElementById('hidden_' + qid).value = val;
                    });
                });
            });
        </script>
    </div>
</body>
</html>